<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PostSaveRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        return [
            "post_name" => ["required", Rule::unique("tb_posts")],
            "post_describe" => ["required", "max:100"],
            "post_cover" => ["required", "string"],
            "post_is_top" => ["nullable", "integer", "max:1", "min:0"],
            "post_is_encrypted" => ["nullable", "integer", "max:1", "min:0"],
            "post_status" => ["nullable", "integer", "max:1", "min:0"],
            "pd_content_raw" => "required",
            "pd_content" => "required",
            "pd_is_reward" => ["nullable", "integer", "max:1", "min:0"],
            "pd_is_comment" => ["nullable", "integer", "max:1", "min:0"],
            "pd_pwd" => "nullable",
            "cate_id" => ["nullable", Rule::exists("tb_category", "cate_id")],
            "tags" => ["nullable", "array", Rule::exists("tb_tag", "tag_id")]
        ];
    }
}
